<!DOCTYPE html>
<html>
<head>
    <title>config form</title>
    <#include "/header.html">
</head>
<body class="bg-white">
<div id="appMain">
    <form class="layui-form layuimini-form" action="" lay-filter="dataForm">
        <div class="layui-form-item">
            <label class="layui-form-label required">参数名</label>
            <div class="layui-input-block">
                <input type="text" name="paramKey" lay-verify="required" lay-reqtext="参数名不能为空" placeholder="输入参数名" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">参数值</label>
            <div class="layui-input-block">
                <input type="text" name="paramValue" lay-verify="required" lay-reqtext="参数值不能为空" placeholder="输入参数值" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark" class="layui-textarea" placeholder="备注信息"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" id="commitBtn" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    layui.use(['form'], function () {
        var form = layui.form,
            $ = layui.$;

        $(document).ready(function () {
            if (parent.formDataId > 0) {
                $.ajax({
                    type: "POST",
                    url: serverUrl('sys/config/info/' + parent.formDataId),
                    data: {},
                    dataType: "json",
                    success: function (result) {
                        if (result.code === 0) {
                            form.val('dataForm', {
                                "paramKey": result.config.paramKey,
                                "paramValue": result.config.paramValue,
                                "remark": result.config.remark
                            });
                        }
                    }
                });
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var params = data.field;
            params.id = parent.formDataId || null;
            var method = parent.formDataId > 0 ? 'update' : 'save';
            submitFormData('sys/config/'+method, params);

            return false;
        });

    });
</script>
</body>
</html>